/*
 * Copyright (c) 2017年11月10日  by XuanWu Wireless Technology Co., Ltd 
 *             All rights reserved  
 */
package com.zml.twelfth.example;

import com.zml.twelfth.example.adapter.GooseAdapter;
import com.zml.twelfth.example.duck.DuckCall;
import com.zml.twelfth.example.duck.Goose;
import com.zml.twelfth.example.duck.MallarDuck;
import com.zml.twelfth.example.duck.Quackable;
import com.zml.twelfth.example.duck.RedheadDuck;
import com.zml.twelfth.example.duck.RubberDuck;
import com.zml.twelfth.example.factory.AbstractDuckFactory;
import com.zml.twelfth.example.factory.CountingDuckFactory;

/**
 * @author <a href="mailto:zhaominglin@wxchina.com">minglin.Zhao</a>
 * @Description
 * @Date 2017/11/10
 * @Version 1.0.0
 */
public class DuckSimulator {
    public static void main(String[] args) {
        DuckSimulator simulator = new DuckSimulator();
        AbstractDuckFactory factory = new CountingDuckFactory();
        simulator.simulator(factory);
    }

    private void simulator(AbstractDuckFactory factory) {
        Quackable mallarDuck = factory.createMallardDuck();
        Quackable duckCall = factory.createDuckCall();
        Quackable rubberDuck = factory.createRubberDuck();
        Quackable redheadDuck = factory.createRedheadDuck();

        System.out.println("\nDuck Simulator: With Abstract Factory");

        simulator(mallarDuck);
        simulator(duckCall);
        simulator(redheadDuck);
        simulator(rubberDuck);

        System.out.println("The ducks quacked " + QuackCounter.getNumberOfDuacks() + "times");
    }

    private void simulator() {
        Quackable mallarDuck = new QuackCounter(new MallarDuck());
        Quackable duckCall = new QuackCounter(new DuckCall());
        Quackable rubberDuck = new QuackCounter(new RubberDuck());
        Quackable redheadDuck = new QuackCounter(new RedheadDuck());
//
//        Quackable mallarDuck = new MallarDuck();
//        Quackable duckCall = new DuckCall();
//        Quackable rubberDuck = new RubberDuck();
//        Quackable redheadDuck = new RedheadDuck();

        Quackable goose = new GooseAdapter(new Goose());

        System.out.println("\nDuck Simulator");

        simulator(mallarDuck);
        simulator(duckCall);
        simulator(redheadDuck);
        simulator(rubberDuck);

        System.out.println("The ducks quacked " + QuackCounter.getNumberOfDuacks() + "times");
    }

    private void simulator(Quackable duck) {
        duck.quack();
    }
}
